package com.zhaoyang.test.druid;

import com.zhaoyang.util.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author 赵扬
 * @time 2020/4/27 08:26
 */

/*
    使用新的工具类
 */
public class DruidDemo2 {
    public static void main(String[] args) {
        PreparedStatement preparedStatement = null;
        Connection connection = null;
        try {
            connection = JDBCUtils.getConnection();
            // 定义sql
            String sql = "insert into s_admin values(null,?,?,1)";
            preparedStatement = connection.prepareStatement(sql);
            // 给占位符赋值
            preparedStatement.setString(1, "zhao");
            preparedStatement.setString(2, "1234");
            int cnt = preparedStatement.executeUpdate();
            System.out.println(cnt);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            // 释放资源
            JDBCUtils.close(preparedStatement, connection);
        }
    }

}
